"""
Case Type   : 事件触发器
Case Name   : 【事件触发器】删除事件触发器，使用IF EXISTS关键字，触发器不存在，不报错
Create At   :   2024/07/16
Owner       :   sungang14
Description :
    预置条件：
        1.删除事件触发器
        drop EVENT TRIGGER if exists eventtri_eventtrigger_0059 CASCADE;
    测试步骤：
        1.使用IF EXISTS关键字删除不存在触发器，不报错
        DROP EVENT TRIGGER IF EXISTS eventtri_eventtrigger_0059;
Expect      : 
        1.提示触发器不存在,不报error
History     : 
"""

import sys
import os
import unittest
from yat.test import Node
from yat.test import macro

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH


class IndexFileDamaged(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.logger.info('----------------this is setup-----------------------')
        self.DB_ENV_PATH = macro.DB_ENV_PATH
        self.DB_INSTANCE_PATH = macro.DB_INSTANCE_PATH
        self.comsh = CommonSH('PrimaryDbBmode')
        self.comsh.execut_db_sql("drop EVENT TRIGGER if exists eventtri_eventtrigger_0059 CASCADE;")

    def test_Index_file_damaged(self):
        self.logger.info("--step1:使用IF EXISTS关键字删除不存在触发器，不报错")
        msg = self.comsh.execut_db_sql("DROP EVENT TRIGGER IF EXISTS eventtri_eventtrigger_0059;")
        self.logger.info(msg)
        self.assertIn(
            f'NOTICE:  event trigger "eventtri_eventtrigger_0059" does not exist, skipping, skipping' and f'DROP EVENT TRIGGER',
            msg)

    def tearDown(self):
        self.logger.info('----------------this is tearDown-----------------------')
        # 无处理
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
